﻿using System;
using System.Text;

namespace PlugNT.Cms.Model
{

    [Serializable]
    public class ArticleInfo
    {

        private int _id;
        private string _no;
        private string _images;
        private string _title;
        private string _subtitle;
        private string _keyword;
        private string _description;
        private string _clsno; 
        private string _clsname;

        private string _clslist;
        private string _contents;
        private string _jumpurl;       //跳转url
        private string _info;          //原创
        private string _author;
        private string _url;
        private int _tip;             //顶
        private string _tag;
        private int _hits = 1;
        private int _orders;
        private bool _commend;        //推荐
        private bool _stick;
        private bool _publish;
        private int _switchs = 0;        //预留
        private DateTime _addtime;
        private string _createpath;
        private string _pagename;
        private string _previouspage;
        private string _nextpage;
        private string _extend1;        //扩展字段1
        private string _extend2;
        private string _extend3;
        private string _extend4;
        private string _extend5;
        private string _color="#ff0000";//标题颜色 #000000
        public string clsname { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string no
        {
            set { _no = value; }
            get { return _no; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string images
        {
            set { _images = value; }
            get { return _images; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string title
        {
            set { _title = value; }
            get { return _title; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string subtitle
        {
            set { _subtitle = value; }
            get { return _subtitle; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string keyword
        {
            set { _keyword = value; }
            get { return _keyword; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string description
        {
            set { _description = value; }
            get { return _description; }
        }
        /// <summary>
        /// 栏目编号
        /// </summary>
        public string clsno
        {
            set { _clsno = value; }
            get { return _clsno; }
        }
        /// <summary>
        /// 栏目字符串
        /// </summary>
        public string clslist
        {
            set { _clslist = value; }
            get { return _clslist; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string contents
        {
            set { _contents = value; }
            get { return _contents; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string jumpurl
        {
            set { _jumpurl = value; }
            get { return _jumpurl; }
        }



        /// <summary>
        /// 
        /// </summary>
        public string info
        {
            set { _info = value; }
            get { return _info; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string author
        {
            set { _author = value; }
            get { return _author; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string url
        {
            set { _url = value; }
            get { return _url; }
        }

        /// <summary>
        /// 
        /// </summary>
        public int tip
        {
            set { _tip = value; }
            get { return _tip; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string tag
        {
            set { _tag = value; }
            get { return _tag; }
        }

        /// <summary>
        /// 
        /// </summary>
        public int hits
        {
            set { _hits = value; }
            get { return _hits; }
        }

        /// <summary>
        /// 
        /// </summary>
        public int orders
        {
            set { _orders = value; }
            get { return _orders; }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool commend
        {
            set { _commend = value; }
            get { return _commend; }
        }
        /// <summary>
        /// 
        /// </summary>
        public bool stick
        {
            set { _stick = value; }
            get { return _stick; }
        }
        /// <summary>
        /// 
        /// </summary>
        public bool publish
        {
            set { _publish = value; }
            get { return _publish; }
        }

        /// <summary>
        /// 
        /// </summary>
        public int switchs
        {
            set { _switchs = value; }
            get { return _switchs; }
        }

        /// <summary>
        /// 
        /// </summary>
        public DateTime addtime
        {
            set { _addtime = value; }
            get { return _addtime; }
        }



        /// <summary>
        /// 
        /// </summary>
        public string createpath
        {
            set { _createpath = value; }
            get { return _createpath; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string pagename
        {
            set { _pagename = value; }
            get { return _pagename; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string previouspage
        {
            set { _previouspage = value; }
            get { return _previouspage; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string nextpage
        {
            set { _nextpage = value; }
            get { return _nextpage; }
        }
        /// <summary>
        /// 标题颜色
        /// </summary>
        public string color
        {
            set { _color = value; }
            get { return _color; }

        }

        /*********************************************************************************/
        private System.Collections.Generic.Dictionary<string, PlugNT.Custom.FieldModel> extfields = null;
        public bool AppExtField(PlugNT.Custom.FieldModel field)
        {
            bool flag = false;
            if (extfields == null)
            {
                extfields = new System.Collections.Generic.Dictionary<string, PlugNT.Custom.FieldModel>();
            }
            if (!extfields.ContainsKey(field.fieldName))
            {
                flag = true;
                extfields.Add(field.fieldName, field);
            }
            return flag;
        }
        public string GetExtFieldValue(string fieldName)
        {
            string strValue = "";
            if (extfields != null && extfields.ContainsKey(fieldName))
            {
                strValue = extfields[fieldName].fieldValue;
            }
            return strValue;
        }
        public string[] GetExtFieldInsertSqlString()
        {
            string[] strArr = new string[2] { "", "" };
            if (extfields != null)
            {
                StringBuilder sbFieldName = new StringBuilder();
                StringBuilder sbFieldValue = new StringBuilder();
                foreach (PlugNT.Custom.FieldModel info in extfields.Values)
                {
                    sbFieldName.Append("," + info.fieldName);
                    if (info.fieldType == PlugNT.Custom.FieldType.integerType)
                    {
                        sbFieldValue.Append("," + info.fieldValue);
                    }
                    else
                    {
                        sbFieldValue.Append(",'" + info.fieldValue + "'");
                    }
                }
                strArr[0] = sbFieldName.ToString();
                strArr[1] = sbFieldValue.ToString();
            }
            return strArr;
        }
        public string GetExtFieldUpdateSqlString()
        {
            string strValue = "";
            if (extfields != null)
            {
                StringBuilder sbFieldNameValue = new StringBuilder();
                foreach (PlugNT.Custom.FieldModel info in extfields.Values)
                {
                    if (info.fieldType == PlugNT.Custom.FieldType.integerType)
                    {
                        sbFieldNameValue.Append("," + info.fieldName + "=" + info.fieldValue);
                    }
                    else
                    {
                        sbFieldNameValue.Append("," + info.fieldName + "='" + info.fieldValue + "'");
                    }
                }
                strValue = sbFieldNameValue.ToString();
            }
            return strValue;
        }


        /*********************************************************************************/


        /*
         
         
        /// <summary>
        /// 扩展字段
        /// </summary>
        public System.Collections.Generic.Dictionary<string,object> extend = null;

        /// <summary>
        /// 构造函数
        /// </summary>
        public ArticleInfo()
        {
            extend = new System.Collections.Generic.Dictionary<string, object>();
        }

        public void InitExtend(System.Data.DataRow dr)
        {
            if (dr == null)
            {
                foreach (string key in PlugNT.Custom.WebConfig.ExtendColumns.Keys)
                {
                    extend.Add(key, "null");
                }
            }
            else
            {
                foreach (string key in PlugNT.Custom.WebConfig.ExtendColumns.Keys)
                {
                    extend.Add(key, dr[key].ToString());
                }
            }
        }

        /// <summary>
        /// 设置扩展
        /// </summary>
        /// <param name="extName"></param>
        /// <param name="extValue"></param>
        /// <returns></returns>
        public bool SetExtend(string extName, object extValue)
        {
            bool flag = true;
            if (extend.ContainsKey(extName))
            {
                extend[extName] = extValue;
            }
            else
            {
                flag = false;
            }
            return flag;
        }

        /// <summary>
        /// 获取扩展
        /// </summary>
        /// <param name="extName"></param>
        /// <returns></returns>
        public object GetExtend(string extName)
        {
            object extValue = "null";
            extend.TryGetValue(extName, out extValue);
            return extValue;
        }




        public static System.Collections.Generic.List<string> propertys = null;
        static ArticleInfo()
        {
            propertys = new System.Collections.Generic.List<string>();
            propertys.Add("id");
            propertys.Add("no");
            propertys.Add("images");
            propertys.Add("title");
            propertys.Add("subtitle");
            propertys.Add("keyword");
            propertys.Add("description");
            propertys.Add("clsno");
            propertys.Add("clslist");
            propertys.Add("contents");
            propertys.Add("jumpurl");
            propertys.Add("info");
            propertys.Add("author");
            propertys.Add("url");
            propertys.Add("tip");
            propertys.Add("tag");
            propertys.Add("hits");
            propertys.Add("orders");
            propertys.Add("commend");
            propertys.Add("stick");
            propertys.Add("publish");
            propertys.Add("switchs");
            propertys.Add("addtime");
            propertys.Add("createpath");
            propertys.Add("pagename");
            propertys.Add("previouspage");
            propertys.Add("nextpage");


            foreach (string  key in PlugNT.Custom.WebConfig.ExtendColumns.Keys)
            {
                propertys.Add(key);
            }

        }

        /// <summary>
        /// 是否存在属性
        /// </summary>
        /// <param name="proName"></param>
        /// <returns></returns>
        public static bool ExistsProperty(string proName)
        {
            return propertys.Contains(proName);
        }

        */

    }
}
